package org.lsy;

import java.util.Arrays;
import java.util.stream.Collectors;

/**
 * @author SHIYUAN
 * @version 1.0
 */
public class Advanced {

    public static int[][] backPackII(int m, int[] A, int[] V) {
        if (A == null || A.length == 0 || V == null || V.length == 0) {
            return null;
        }
        int n = A.length;
        int[][] dp = new int[n + 1][m + 1];
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                if (A[i - 1] > j) {
                    dp[i][j] = dp[i-1][j];
                } else {
                    dp[i][j] = Math.max(dp[i-1][j], dp[i-1][j - A[i - 1]] + V[i - 1]);
                }
            }
        }
        System.out.println(n);
        System.out.println(m);
        return dp;
    }

    public static void main(String[] args) {
        //工人总数
        int m = 10;
        //金矿需要的工人数量
        int[] A = new int[]{5,5,3,3,3};
        //金矿的价值
        int[] V = new int[]{500,500,200,200,200};
        int[][] packII = backPackII(m, A, V);
        for (int[] array : packII) {
            System.out.println(Arrays.stream(array).mapToObj(String::valueOf).collect(Collectors.joining(",")));
        }
    }
}
